#ifndef HANDLE_H
#define HANDLE_H

#include <QGraphicsEllipseItem>
#include <QVector>
#include <QBrush>
#include <QColor>

class CurveItem;

class Handle : public QGraphicsEllipseItem
{
public:
    enum { Type = UserType + 1 };
    Handle(CurveItem *handledCurve, QVector<QPointF> *controlPoints,
           int i, qreal radius);

    void SetHasCursor(bool value);
    bool GetHasCursor();
    virtual int GetIndex() const;
    virtual CurveItem * GetCurve();

    int type() { return Type; }


protected:
    QRectF boundingRect() const;
    void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
    void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
    void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
    QVariant itemChange(GraphicsItemChange change, const QVariant &value);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QBrush GetDefaultBrush();
    QVector<QPointF> *m_cPoints;
    qreal m_radius;
    int m_i;

private:
    CurveItem *m_curve;
    bool m_hasCursor;
};

namespace Consts
{
    const QBrush HandleHoverInBrush(Qt::green);
    const QBrush HandleHoverOutBrush(Qt::NoBrush);
    const QBrush HandlePressBrush(Qt::yellow);

    const QBrush HandleFirstBrush(Qt::white);
    const QBrush HandleLastBrush(Qt::black);

    const double WeightScrollPrecision = 0.1;
}
#endif // HANDLE_H
